#include <QtCore/QSettings>
#include "qastrologer.h"
#include "qproxydialog.h"


QProxyDialog::QProxyDialog(QWidget *parent) : QDialog(parent)
{
    setupUi(this);
    this->init();
    this->connect(bbOkCancel, SIGNAL(accepted()), this, SLOT(accept()));
    this->connect(bbOkCancel, SIGNAL(rejected()), this, SLOT(reject()));
}

bool QProxyDialog::init()
{
    // size mode
    this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
    // read settings
    this->readSettings();

    return true;
}

void QProxyDialog::readSettings()
{
    QSettings settings(QAS_APP_NAME, "proxy");

    bool enable = settings.value("enable").toBool();
    gbEnable->setChecked(enable);
    QString address = settings.value("address").toString();
    edAddress->setText(address);
    int port = settings.value("port").toInt();
    spPort->setValue(port);
    QString username = settings.value("username").toString();
    edUsername->setText(username);
    QString password = settings.value("password").toString();
    edPassword->setText(password);
    QString domain = settings.value("domain").toString();
    edDomain->setText(domain);
}

void QProxyDialog::writeSettings()
{
    QSettings settings(QAS_APP_NAME, "proxy");

    settings.setValue("enable", gbEnable->isChecked());
    settings.setValue("address", edAddress->text());
    settings.setValue("port", spPort->value());
    settings.setValue("username", edUsername->text());
    settings.setValue("password", edPassword->text());
    settings.setValue("domain", edDomain->text());
}

void QProxyDialog::accept()
{
    this->writeSettings();
    QDialog::accept();
}
